﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace ConsoleServiceHost
{
	class Program
	{
		internal static ServiceHost m_host;
		internal static ServiceHost m_host2;

		static void Main(string[] args)
		{
			try
			{
				StartService();
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
				Console.WriteLine(ex.StackTrace);
			}

			Console.WriteLine("Service statrted");
			Console.WriteLine("Press any key to stop service");

			Console.ReadLine();

			StopService();
		}

		internal static void StartService()
		{
			m_host = new ServiceHost(typeof(WcfServiceDuplex.Service1));
			m_host2 = new ServiceHost(typeof(WcfServiceDuplex.MyDuplexService));

			m_host.Open();
			m_host2.Open();
		}

		internal static void StopService()
		{
			if (m_host != null && m_host.State == CommunicationState.Opened)
			{
				m_host.Close();

				Console.WriteLine("Service1 ended run");
			}

			if (m_host2 != null && m_host2.State == CommunicationState.Opened)
			{
				m_host2.Close();

				Console.WriteLine("MyDuplexService ended run");
			}

			System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));

		}

	}
}
